<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>添加学生信息</title>
	</head>
	<body>
		<h1>添加学生信息</h1>
		<form action="/student/add" method="post" id="form">
			<ul>
				<li>
					<label>
						姓名：<input type="text" name="name" />
					</label>
				</li>
				<li>
					<label>
						年龄：<input type="number" name="age" />
					</label>
				</li>
				<li>
					<label>
						专业：
						<select name="major">
							<option value="计算机网络">计算机网络</option>
							<option value="前端">前端</option>
							<option value="安卓">安卓</option>
							<option value="java">java</option>
						</select>
					</label>
				</li>
				<li>
					<label>
						性别：<input type="radio" name="sex" id="sex" value="m"  checked/>男
							  <input type="radio" name="sex" id="sex" value="f" />女
						     
						      
						
					</label>
				</li>
				<li>
					<label>
						电话：<input type="number" name="tel" />
					</label>
				</li>
				<li>
					<label>
						学号：<input type="number" name="stuid" />
					</label>
				</li>
				<li>
					<label>
						籍贯：<input type="text" name="home" />
					</label>
				</li>
			</ul>
			
			
			<div id="tis">
				
			</div>
			
			<input type="submit" value="添加学生" />
		</form>
		
		
	</body>
	
	<script src="/jquery/dist/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	
	<script type="text/javascript">
		
		$("#form").on('submit',function(){
			$.ajax({
				type:"post",
				url:$(this).attr.action,
				async:true,
				data:$(this).serialize(),
				success:function(data){
					if(data.err_num === 1){
						$("#tis").html("服务器链接失败")
					}else if(data.err_num ===0 ){
						var i = 5;
						$("input[type='submit']").attr('disabled',true)
						var timer = setInterval(function(){
							$("#tis").html("添加成功"+i+"秒后跳转")
							i--;
							if(i==0){
								clearInterval(timer)
								window.location.href ='/student'
							}
						},1000)
						
					}
				}
			});
			
			return false;
		})
		
		
	</script>
	
</html>
